package com.yanqu.road.server.logic.activity.condition.metaspace;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.activity.MetaSpaceProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.RandomHelper;

import java.math.BigInteger;

public class DayFirstInnCondition extends BaseActivityCondition {
    public DayFirstInnCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        BigInteger value = getValue();
        if (value.compareTo(BigInteger.ONE) != 0) {
            //等于 1 才有判断
            setValue(BigInteger.ONE);
            int rate = activityConditionInfo.getParamList().get(1).intValue();
            long randomNum = RandomHelper.nextLong(1000);
            if (randomNum > rate) {
                return;
            }
            // 发送去跨服判断是否可领奖
            MetaSpaceProto.SendTriggerToCrossReqMsg.Builder msg = MetaSpaceProto.SendTriggerToCrossReqMsg.newBuilder();
            msg.setActivityId(activityInfo.getActivityId());
            msg.setConditionId(activityConditionInfo.getConditionId());
            player.sendPacket(CrossProtocol.C_CROSS_META_SPACE_TRIGGER, msg);
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.DAY_FIRST_INN.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {

    }
}
